package cn.uc.ucgc.community.upgrade.shell;

import java.io.File;
import java.util.List;

import cn.uc.ucgc.community.upgrade.Constants;
import cn.uc.ucgc.community.upgrade.Task;
import cn.uc.ucgc.community.upgrade.Utils;

public class ShellTask extends Task {
    private List<ShellJob> shellJobs;
    //执行脚本对应的运行路径信息
    private File homePath;

    public ShellTask(List<ShellJob> shellJobs) {
        super.setTaskDesc("Shell Cmd Task");
        this.shellJobs = shellJobs;
    }

    @Override
    public void doTask(StringBuilder sb) throws Exception {
        if (null == shellJobs || shellJobs.isEmpty()) {
            sb.append(Constants.TASK_RESULT_NOTASK_SUFFIX);
            return;
        }

        //顺序执行shell脚本任务
        for (ShellJob job : shellJobs) {
            if (null == job) {
                continue;
            }
            //执行对应的脚本
            Utils.exeShellCmd(homePath, job.getShellCmd(), job.getCmdParams());
        }
    }
}
